/**
 * 
 */
package com.yzd.netmonitor.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author lipeng
 *
 */
public class NumberHelper {
	//RoundingMode BigDecimal的四舍五入
	public static BigDecimal getBigDecimal(String money,int scale,RoundingMode model){
		if(money == null || "".equals(money.trim())){
			new BigDecimal("0.00").setScale(scale, model);
		}
		if(scale<0 || model == null){
			throw new RuntimeException("error param");
		}
		try{
			return new BigDecimal(money).setScale(scale, model);
		}catch(Exception e){
			e.printStackTrace();
			throw new RuntimeException("generate bigdecimal wrong params money :"+money+" scale : "+scale);
		}
	}
	
	public static BigDecimal getBigDecimal(String money){
		if(money == null || "".equals(money.trim())){
			new BigDecimal("0.00");
		}
		try{
			return new BigDecimal(money);
		}catch(Exception e){
			e.printStackTrace();
			throw new RuntimeException("generate bigdecimal wrong params money :"+money);
		}
	}
	
	public static BigDecimal getBigDecimalRoundHalfUpOfDoubleScale(String money){
		return getBigDecimal(money,2, RoundingMode.HALF_UP);
	}
	
}
